package com.share.web.action.sysmgr.privilege;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.share.bean.sysmgr.privilege.PrivilegeResourceItem;
import com.share.service.sysmgr.privilege.PrivilegeResourceItemManager;
import com.share.web.action.base.BaseActionSupport;


/**
 * <p>
 * Title：资源保护类别Action
 * </p>
 * <p>
 * Description：
 * </p>
 * 
 * @Author 杨浩泉
 * @Date 2010-3-11
 */
@Controller
@Scope("prototype")
public class PrivilegeResItemAction extends BaseActionSupport implements
		ServletRequestAware {

	private static final long serialVersionUID = 1L;

	private PrivilegeResourceItem resItem;

	@Resource
	private PrivilegeResourceItemManager resItemMgr;

	private HttpServletRequest request;

	private String type;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setResItemMgr(PrivilegeResourceItemManager resItemMgr) {
		this.resItemMgr = resItemMgr;
	}

	public String addResourceItem() throws Exception {

		resItemMgr.saveResourceItemManager(resItem);

		return "addSuc";
	}

	/* 查询所有资源类型 */
	public String queryResourceItem() throws Exception {
		request.setAttribute("resItems", resItemMgr.queryResourceItemManager());

		return "queryResItem";
	}

	/* 按ID查询资源类型 */
	public String queryByIdResItem() throws Exception {
		request.setAttribute("resItemsById", resItemMgr.queryByIdResourceItemManager(resItem.getId()));
		if ("queryByUpdateResItem".equals(type)) {
			type = null ;
			return "queryByUpdateResItem";
		} else {
			return "queryResItemById";
		}
	}

	public String updateResourceItem() throws Exception {

		resItemMgr.updateResourceItemManager(resItem) ;

		return "updateLoad";
	}
	
	public String deleteResourceItem() throws Exception {

		resItemMgr.deleteResourceItemManager(resItem.getId()) ;

		return "addSuc";
	}

	public PrivilegeResourceItem getResItem() {
		return resItem;
	}

	public void setResItem(PrivilegeResourceItem resItem) {
		this.resItem = resItem;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

}
